package com.linghui.videoplus.ipai.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.linghui.videoplus.ipai.R;


public class MenuLayout extends LinearLayout {
	protected final static int MENU_HOME = 0;
	protected final static int MENU_CAMERA = 1;
	protected final static int MENU_PHOTO = 2;
	
	
	private LinearLayout[] layouts = new LinearLayout[3];
	private ImageView[] imageViews = new ImageView[3];
	private TextView[] textViews = new TextView[3];

	public MenuLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public MenuLayout(Context context) {
		super(context);
		init();
	}

	private void init() {
		LayoutInflater.from(getContext()).inflate(R.layout.adapter_menu, this);
		
		layouts[MENU_HOME] = (LinearLayout) this.findViewById(R.id.homeLL);
		layouts[MENU_CAMERA] = (LinearLayout) this.findViewById(R.id.cameraLL);
		layouts[MENU_PHOTO] = (LinearLayout) this.findViewById(R.id.photoLL);
		
		imageViews[MENU_HOME] = (ImageView) this.findViewById(R.id.homeImageView);
		imageViews[MENU_CAMERA] = (ImageView) this.findViewById(R.id.cameraImageView);
		imageViews[MENU_PHOTO] = (ImageView) this.findViewById(R.id.photoImageView);
		
//		clearLayoutsFocus();
	}
	
	/**
	 * 
	 */
//	private void clearLayoutsFocus() {
//		for (LinearLayout layout : layouts) {
//			layout.setBackgroundResource(R.drawable.maintab_toolbar_bg);
//		}
//	}
	
	/**
	 * 
	 * @param id
	 */
	public void setFocus(int id) {
//		clearLayoutsFocus();
		switch (id) {
		case R.id.homeLL:
//			layouts[MENU_HOME].setBackgroundResource(R.drawable.btn_hot_down);
			imageViews[MENU_HOME].setBackgroundResource(R.drawable.btn_hot_down);
			break;
		case R.id.cameraLL:
//			layouts[MENU_CAMERA].setBackgroundResource(R.drawable.home_btn_bg_d);
			break;
		case R.id.photoLL:
//			layouts[MENU_PHOTO].setBackgroundResource(R.drawable.btn_photo_down);
			imageViews[MENU_PHOTO].setBackgroundResource(R.drawable.btn_photo_down);
			break;
		}
	}
	
	public void setOnClickListener(OnClickListener l) {
		for (LinearLayout layout : layouts) {
			layout.setOnClickListener(l);
		}
		for (ImageView imageView : imageViews) {
			imageView.setOnClickListener(l);
		}
//		for (TextView textView : textViews) {
//			textView.setOnClickListener(l);
//		}
	}

}
